﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;

public partial class Events : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        bool flag = ValidateFields();
        if (flag)
        {
            DataTable myDt = new DataTable();
            myDt = GenericDAL.SetRegistration(txtName.Text, txtEmail.Text, txtPhone.Text, ddlTimeSlot.SelectedItem.Text, (rdoBoth.Checked == true ? rdoBoth.Text : rdoCSharp.Text), (chkSubscribe.Checked == true ? 1 : 0));
            if (myDt.Rows.Count > 0)
            {
                if (myDt.Rows[0][0].ToString() == "DUPLICATE")
                {
                    lblResult.Text = "Registration already exists on this email id...";
                    lblResult.ForeColor = Color.Red;
                }
                else if (myDt.Rows[0][0].ToString() == "SUCCESS")
                {
                    lblResult.Text = "Registration Success";
                    lblResult.ForeColor = Color.Green;
                }
                else
                {
                    lblResult.Text = myDt.Rows[0][0].ToString();
                    lblResult.ForeColor = Color.Red;
                }
            }
        }
    }

    private bool ValidateFields()
    {
        bool flag = true;
        lblResult.ForeColor = Color.Red;

        if (txtName.Text == "")
        {
            lblResult.Text = "Please enter Name...";
            txtName.Focus();
            flag = false;
            return flag;
        }

        if (txtEmail.Text == "")
        {
            lblResult.Text = "Please enter Email...";
            txtEmail.Focus();
            flag = false;
            return flag;
        }

        if (txtCEmail.Text == "")
        {
            lblResult.Text = "Please enter Confirmation Email...";
            txtCEmail.Focus();
            flag = false;
            return flag;
        }

        if (txtEmail.Text != txtCEmail.Text)
        {
            lblResult.Text = "Email and Confirm Email must match...";
            txtCEmail.Focus();
            flag = false;
            return flag;
        }

        if (txtPhone.Text == "")
        {
            lblResult.Text = "Please enter Phone No...";
            txtPhone.Focus();
            flag = false;
            return flag;
        }

        if (ddlTimeSlot.SelectedItem.Text == "--Select Time--")
        {
            lblResult.Text = "Please choose a Time Slot...";
            flag = false;
            return flag;
        }

        return true;
    }
}